﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAO;
using DTO;
using DAO.PO;
using DTO.PO;

namespace BUS
{
    public class ImportInventorycs
    {
        public void ImportInventory(int invtId, string unit, int qty, int siteId)
        {
            int qtyStore = 0;
            InventoryDAO invt = new InventoryDAO();
            
            switch (unit)
            {
                case "CS": // don vi thung (chan)
                    qtyStore = qty*invt.GetInvtPurchaseInfo(invtId).ConvertUnit;
                    break;
                case "EA": // don vi goi (le)
                    qtyStore = qty;
                    break;
            }

            InventStoreDAO inventStoreDao = new InventStoreDAO();

            /*if(!inventStoreDao.InStore(invtId, siteId))                // neu hang` chua co trong kho
                inventStoreDao.InsertInventoryStore(inventStore);

            /*
            else*/
            inventStoreDao.UpdateInventoryStore(invtId, siteId, qtyStore);    // neu hang` co trong kho (cap nhat so luong)*/
        }

        public void CreateReceipt(string receiptNum, DateTime date, char type, int qtyTotal, int poNumber)
        {
            ReceiptDAO receiptDAO = new ReceiptDAO();
            Receipt receipt = new Receipt();
            receipt.ReceiptName = receiptNum;
            receipt.Date = date;
            receipt.Type = type;
            receipt.QtyTotal = qtyTotal;
            receipt.PoNumber = poNumber;

            receiptDAO.InsertReceipt(receipt);
        }

        // Update bang PO_Trans de bao cao

        public void CreateTrans(int invtId, int receiptNum, int qty, int unit, int siteId)
        {
            TransDAO transDAO = new TransDAO();
            Trans trans = new Trans();
            trans.InvenId = invtId;
            trans.ReceiptNumber = receiptNum;
            trans.Qty = qty;
            trans.Unit = unit;
            trans.SiteId = siteId;

            transDAO.InsertTrans(trans);
        }
    }
}
